package com.onec.service.route.service.base.impl;


import com.onec.service.api.dto.request.route.RouteReq;
import com.onec.service.api.enums.SystemTypeEnum;
import com.onec.service.api.enums.error.RouteErrorEnum;
import com.onec.service.api.exception.RouteException;
import com.onec.service.route.entity.TradeRuleInfo;
import com.onec.service.route.service.base.BaseTradeConfigDefaultService;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 商户黑名单信息验证：卡号黑名单，身份证黑名单，手机号黑名单：
 *
 * @author onec
 * @see
 * @since 20210105
 */
@Service(value = "MERCHANT_BLOCK_INFO_SERVICE")
public class MerchantBlockInfoServiceImpl extends BaseTradeConfigDefaultService {


    /**
     * 卡号黑名单，身份证黑名单，手机号黑名单：
     *
     * @param routeReq tradeRuleInfo
     * @return ResponseMerchant
     */
    @Override
    public boolean beforeExecute(RouteReq routeReq, TradeRuleInfo tradeRuleInfo) {
        // 交易规则不存在当作成功;
        if (Optional.ofNullable(tradeRuleInfo.getValue()).isEmpty()) {
            return false;
        }
        if (blockInfoService.isBlockType(routeReq.getCardNo(), SystemTypeEnum.CARD_NO)) {
            throw new RouteException(RouteErrorEnum.MERCHANT_CARD_BLOCK, "");
        }
        if (blockInfoService.isBlockType(routeReq.getIdCard(), SystemTypeEnum.ID_CARD)) {
            throw new RouteException(RouteErrorEnum.MERCHANT_ID_CARD_BLOCK, "");
        }
        if (blockInfoService.isBlockType(routeReq.getPhone(), SystemTypeEnum.PHONE)) {
            throw new RouteException(RouteErrorEnum.MERCHANT_PHONE_BLOCK, "");
        }
        return false;
    }

    /**
     * 交易处理成功：添加相对应的数据。
     *
     * @param
     * @return ResponseOnline
     */
    @Override
    public boolean afterExecute(RouteReq ruleParam) {


        return false;
    }

}
